# -- coding: utf-8 --
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
import HTMLTestRunner
import unittest
import threading
import multiprocessing
# 进程

# 驱动所在位置
webDriver = 'D:\pycharm\ycb2b_webscript\drivers\chromedriver.exe'
# 创建wbDriver对象，指明使用chrome浏览器驱动
wd = webdriver.Chrome(webDriver)
# 设置最大等待时长
wd.implicitly_wait(10)

def login_on():
    # 打开
    wd.get('http://ycbtestefq.youchebao.cn:7080/')

    # 输入用户名
    username = wd.find_element_by_id('username')
    username.send_keys('18649325562')

    # 输入密码
    password = wd.find_element_by_id("password")
    password.send_keys("00000000")

    # 输入验证码
    captcha = wd.find_element_by_id('captcha')
    captcha.send_keys('1234')

    # 点击登录
    submit = wd.find_element_by_class_name('input-button')
    submit.click()

    # 点击角色框
    select = wd.find_element_by_id('roleSelect')
    select.click()

    # 创建Select对象
    select1 = Select(wd.find_element_by_id("roleSelect"))
    # 选择角色
    select1.select_by_visible_text("系统管理员")

    # 确定
    submit1 = wd.find_element_by_class_name('lg-btn')
    submit1.click()

    handle = wd.current_window_handle
    print(f"当前handle"+handle)

    # 点击第一个贷款单
    dkd = wd.find_element_by_css_selector('li[treedataindex="8"]')
    dkd.click()

    # 点击第二个
    dkdt = wd.find_element_by_css_selector('li[treedataindex="22"]')
    dkdt.click()

    handle1 = wd.current_window_handle
    print(f"当前handle"+handle1)

    # windows = wd.window_handles
    # wd.switch_to_window(windows[-1])

    # 输入贷款单编号
    wd.switch_to_frame('LOAN_LST')
    sendDkdNum = wd.find_element_by_css_selector('input[type="text"][name="order_no"][class="l-text-field"]')
    sendDkdNum.send_keys('20201223000004')
    #wd.switch_to_default_content()

    # 搜索'
    time.sleep(3)
    search = wd.find_element_by_css_selector('#maingrid > div.l-panel-topbar > div > div:nth-child(1) > span')
    search.click()

    listInfo = wd.find_element_by_css_selector('#maingrid\|2\|r1001\|c102 > div')
    listInfo.click()

    Info = wd.find_element_by_css_selector('#maingrid > div.l-panel-topbar > div > div:nth-child(11)')
    Info.click()

login_on()
# t1 = threading.Thread(target=login_on(),args=())
# t2 = threading.Thread(target=login_on(),args=())
# t1.start()
# t2.start()



